function zl = genzlist(T, K)
%GENZLIST generates list of Z values used in mme_embedpart
% ZLIST is a M by N matrix, where M is at most 2^N - 1. Each row of ZLIST
% is a possible Z(bits to change)
  N = 2^K - 1;
  u = pow2(N-1:-1:0);
  total = 0;
  count = 0;
  parfor i = 0:T
      total = total + nchoosek(N, i);
  end
  zl = zeros(total, N, 'uint8');
  for i = 1:2^N
    z = ~bitand(u,i);    % z - which bits to change
    if sum(z) > T
        continue % ignore this value
    end
    count = count + 1;
    zl(count,:) = z;
  end
end
